package cn.edu.tju.ldj.analytics.alphas;

import cn.edu.tju.ldj.analytics.vo.Contract;

public class Alpha2 extends IAlphaEngine{
	public void processSimulation(Contract ct, boolean isOutJson) {
		if (isOutJson) {
			logger.info("\n\nAlpha2 ------------" + ct.getCtrctName()
					+ "-------- START");
		}
		strategyTest(ct, isOutJson);
		if (isOutJson) {
			logger.info("Alpha2 ------------" + ct.getCtrctName()
					+ "--------  END");
		}
	}
	
	protected void getWhereWeAre() {
		if(isSlopeRise("avg4")){//长期趋势为涨势
			if(isSlopeRise("avg3")){//中期趋势为涨
				if(curPosition <= 0){//上涨中
					getWhatToDo(POSITION_BUY_HAV);
					logInfo("上行行情中，持重多仓");
				}
			}else if(isSlopeFall("avg3")){//中期趋势为跌
				if(isLineOver("avg3", "avg4") && isSuccessiveBelowAvg("avg3", WINDOW_INDEX/4)){
//					getWhatToDo(POSITION_SEL_HAV);
//					logInfo("下行行情中，持重空仓");
				}
				if(curPosition > 0){
					getWhatToDo(POSITION_INIT);
					logInfo("上行行情结束，平仓观望");
				}
			}else{//中期趋势为震荡
				if(isSlopeFall("avg1") && isSlopeFall("avg2")){
					if(curPosition > 0){
						getWhatToDo(POSITION_INIT);
						logInfo("上行行情结束，平仓观望");
					}
				}
			}
		}else if(isSlopeFall("avg4")){//长期趋势为跌
			if(curPosition > 0){
				getWhatToDo(POSITION_INIT);
				logInfo("下行行情，平掉多仓");
			}
			if(isSlopeFall("avg3")){//中期趋势为跌
				if(curPosition >= 0){
//					getWhatToDo(POSITION_SEL_HAV);
//					logInfo("长中期均为下跌，应持空仓");
				}
			}else if(isSlopeRise("avg3") || isSlopeShock("avg3")){//下降趋势下，中短期出现回调
				if(isSuccessiveOverAvg("avg3", WINDOW_INDEX/4)){
					if(curPosition < 0){
						getWhatToDo(POSITION_INIT); //涨势结束信号，平仓
						logInfo("跌势结束信号，平仓");
					}
				}else if(isSuccessiveBelowAvg("avg3", WINDOW_INDEX/4)){
//					getWhatToDo(POSITION_SEL_HAV);
//					logInfo("下行行情中，持重空仓");
				}
			}
		}else{//长期趋势接近横盘整理中
			if(isSlopeFall("avg3")){//中期趋势下跌，适合开空仓
				if (isSuccessiveBelowAvg("avg3", WINDOW_INDEX / 4)) {
//					getWhatToDo(POSITION_SEL_HAV);
//					logInfo("开始下跌信号，持重空仓");
				}
			}else if(isSlopeRise("avg3")){//中期趋势为涨
				if(isSuccessiveOverAvg("avg3", WINDOW_INDEX/6)){
					if(curPosition < 0){
						getWhatToDo(POSITION_INIT); //涨势结束信号，平仓
						logInfo("跌势结束信号，平仓");
					}
					if(isSuccessiveOverAvg("avg3", WINDOW_INDEX/4)){
						getWhatToDo(POSITION_BUY_HAV);
						logInfo("开多仓信号，持重多仓");
					}
				}
				
			}else{//中期也在纠结，横盘整理中
				getWhatToDo(POSITION_INIT);
				logInfo("中长期纠结行情，平仓观望");
				if(isSlopeFall("avg2")){//纠结中出现短期开空仓信号，可能是空头行情的开始，中空试探
					if(isLineOver("avg3", "avg2") && isLineOver("avg2", "avg4") && curPosition >= 0){
//						getWhatToDo(POSITION_SEL_HAV);
//						logInfo("开始下跌端倪，重空");
					}
				}else if(isSlopeRise("avg2")){//纠结中出现短期上涨信号，如果满足下述条件考虑开多仓
					if(isSuccessiveOverAvg("avg3", WINDOW_INDEX/4)){
						if(curPosition <= 0){
							getWhatToDo(POSITION_BUY_HAV);
							logInfo("开多仓信号，持重多仓");
						}
					}
				}else{//短期都在纠结，震荡中
					getWhatToDo(POSITION_INIT); //横盘整理，平仓观望
					logInfo("横盘整理，平仓观望");
				}
			}
		}
	}
}
